﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrangTrai.Data.Utils;
using System.Data.SqlClient;
using log4net;

namespace TrangTrai.Data.DAO
{
    public class ReportDAO
    {
        SqlConnection con;
        SqlCommand command;
        SqlDataReader re=null;
        public static ReportsDataContext context = new ReportsDataContext(ConnectionClass.getConnectionString());
        private static readonly ILog log = LogManager.GetLogger(typeof(ReportDAO).Name);
        public ReportDAO()
        {
            init();

        }
        private void init()
        {
            try
            {
                con = ConnectionClass.getConnection();
                command = con.CreateCommand();
            }
            catch (Exception e)
            {
                
                 log.Error("init", e);
            }
        }
        public ChoAnReport[] getFoodReport(int ao, int seasonId, DateTime toDate) {
            try
            {
                ChoAnReport[] foodReport = context.getThucAnReport(ao, seasonId, toDate).ToArray();
                return foodReport;
            }
            catch (Exception e)
            {
                
                log.Error("getFoodReport", e);
                return null;
            }
        }
        #region bao cao ve moi truong
        public EnvReport[] getEnReport(int aoid, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getEnvReport(aoid, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {
               log.Error("getEnReport", e);
                return null;
            }
        }
        public DoKiemReport[] getDoKiemReport(int aoId, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getDoKiemReport(aoId, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {

                log.Error("getDoKiemReport", e);
                return null;
            }
        }
        public DoOxiHoaReport[] getDoOxiHoaReport(int aoId, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getDoOxiHoaReport(aoId, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {
                log.Error("getDoOxiHoaReport", e);
                return null;
            }
        }
        public DoTrongReport[] getDoTrongReport(int aoId, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getDoTrongReport(aoId, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {
                log.Error("getDoTrongReport", e);
                return null;
            }
        }
        public DoManReport[] getDoManReport(int aoId, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getDoManReport(aoId, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {
                log.Error("getDoManReport", e);
                return null;
            }
        }

        public DoTangTruongReport[] getDoTangTruong(int aoId, int seasonId, DateTime toDate)
        {
            try
            {
                return context.getDoTangTruongReport(aoId, seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {

                log.Error("getDoTangTruong", e);
                return null;
            }
        }
        public HoachatReport[] getHoaChatReport(int aoSeasonId, DateTime toDate) {
            try
            {
                return context.getHoaChatReport(aoSeasonId, toDate).ToArray();
            }
            catch (Exception e)
            {

                log.Error("getHoaChatReport", e);
                return null;
            }
        }
        public SummaryReport[] getSummaryReports(int seasonId, DateTime toDate) {
            try
            {
                return context.getSummaryReport(seasonId, toDate).ToArray();
            }
            catch (Exception e)
            {
                
                log.Error("getSummaryReports", e);
                return null;
            }
        }
        public SummaryReport[] getStandardDataReport(int numberOfTom, int tomAge) {
            try
            {
                return context.getStandardDataReport(numberOfTom, tomAge).ToArray();
            }
            catch (Exception e)
            {

                log.Error("getStandardDataReport", e);
                return null;
            }
        }

        #endregion


      
    }
}
